﻿package com.designoutput.ui
{
    import flash.events.*;
    import flash.text.*;
    import flash.utils.*;

    public class Hover extends TextField
    {
        internal var p:DesignoutputCard;
        internal var lastshow:uint = 0;
        internal var id:uint;

        public function Hover(target:DesignoutputCard)
        {
            p = target;
            defaultTextFormat = new TextFormat("Verdana, Helvetica, San-serif", 12, 0);
            background = true;
            backgroundColor = 0xF4FF98;
            border = true;
            borderColor = 0;
            height = 16;
            autoSize = TextFieldAutoSize.LEFT;
            visible = false;
        }

        public function setText(text:String) : void
        {
            this.text = text;
            id = setTimeout(show, lastshow + 800 > getTimer() ? (100) : (1500));
        }

        private function show() : void
        {
            visible = true;
            x = stage.mouseX + width + 10 > stage.stageWidth ? (stage.stageWidth - 10 - width) : (stage.mouseX + 5);
            y = stage.mouseY + 20;
        }

        public function hideEvent(event:MouseEvent) : void
        {
            hide();
        }

        public function hide() : void
        {
            if (visible)
            {
                lastshow = getTimer();
                visible = false;
            }
            clearTimeout(id);
        }
    }
}
